package com.dev.module_zqc_sleep.activity

import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import com.dev.module_ui_composable.theme.JetComposableTheme
import com.dev.module_zqc_sleep.mvi.ui.ClassifyScreen
import com.dev.module_zqc_sleep.utils.HTTPS_URL

class ClassifyActivity : AppCompatActivity() {

    private val position: Int by lazy { intent.getIntExtra(EXTRA_POSITION, 0) }

    companion object {
        private const val EXTRA_POSITION = "imageName"

        fun start(context: Context, position: Int) {
            val intent = Intent(context, ClassifyActivity::class.java).apply {
                putExtra(EXTRA_POSITION, position)
            }
            context.startActivity(intent)
        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContent {
            JetComposableTheme {
                ClassifyScreen(
                    position = position,
                    onBackClick = { finish() },
                    onPlayAudio = { audioPath, tabName ->
                        navigateToPlayAudio(audioPath, tabName)
                    }
                )
            }
        }
    }

    private fun navigateToPlayAudio(audioPath: String, tabName: String) {
        PlayAudioActivity.start(this, "$HTTPS_URL$audioPath", tabName)
    }

}